# Copyright (C) 2006,2007  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information visit http://carrierclass.net/
#

use strict;
use warnings;

package CCNCore::Model::ServerRouter;

use Jifty::DBI::Schema;

use CCNCore::Record schema {

    column server =>
        references CCNCore::Model::Server,
        is mandatory,
        is immutable,
        is indexed,
        since '0.0.1',
        label is "Server",
        hints is '';

    column ipnet_ip =>
        # MySQL doesn't have a native "inet" type;
        type is 'VARCHAR(16)',
        validator is \&CCN::Framework::Type::IPv4::validator,
        is mandatory,
        is immutable,
        is indexed,
        since '0.0.1',
        label is "Route Network IP";

    column ipnet_mask =>
        # MySQL doesn't have a native "inet" type;
        type is 'VARCHAR(16)',
        validator is \&CCN::Framework::Type::IPv4::validator,
        is mandatory,
        is immutable,
        is indexed,
        since '0.0.1',
        label is "Route Network Mask";

    column router_ip =>
        # MySQL doesn't have a native "inet" type;
        type is 'VARCHAR(16)',
        validator is \&CCN::Framework::Type::IPv4::validator,
        is mandatory,
        since '0.0.1',
        label is "Router IP";

    # XXX PRIMARY KEY ("server","router_ip","ipnet_ip")

};

use CCNCore::Mixin::Active;

sub since { 0.0.1 }
sub authorize_via { qw( server server ) }
sub menu { 'Servers' }

1;

__END__

=pod
-- Extra routing entries for a given server

CREATE TABLE "server_router" (
    "server"            INTEGER NOT NULL REFERENCES server(pk),     --      "Server"
    "ipnet_ip"          inet NOT NULL,                              -- @ip  "Route network IP"
    "ipnet_mask"        inet NOT NULL,                              -- @ip  "Route network mask"
    "router_ip"         inet NOT NULL,                              -- @ip  "Router IP"
    -- of course this is redundant is PostgreSQL since inet stores both IP and mask

    PRIMARY KEY ("server","router_ip","ipnet_ip")
);

=cut
